[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-11-02
-->
[@JGP.head "列表数据管理"/]
[@JGP.body]
    <jgp-div _col="['300','*']" _cunit="px">
        <jgp-div slot="1-1" _row="['40','*']" _runit="px" _aux="true">
            <div slot="1-1">
                <jgp-btn _fn="addGroup">添加分组</jgp-btn>
                <jgp-btn _fn="refreshCache">刷新缓存</jgp-btn>
            </div>
            <jgp-panel slot="2-1" _padding="10px">
                <jgp-tree2 _id="groupTree" _url="/sys/param-api-ctl/query-group-tree"
                           _single="true"
                           _extend="true"
                           _lazy="false"
                           _onclick="chooseGroup"
                           _check="true" _root="下拉数据"
                           _tools="[{'icon':'plus','tip':'添加项','fn':'addList'},
                           {'icon':'trash-o','tip':'删除','fn':'removeAttribute'}]"
                ></jgp-tree2>
            </jgp-panel>
        </jgp-div>

        <jgp-div slot="1-2" _row="['80','*','80','*']" _runit="px">
            <jgp-query slot="1-1" _id="activeGroupQueryForm" _label_width="60px"
                       _action="/sys/param-api-ctl/query-list"
                       _target="activeGroupGrid">
                <jgp-form-group _title="功能组">
                    <jgp-text _name="code" _col="4" _placeholder="功能标识"></jgp-text>
                    <jgp-text _name="name" _col="4" _placeholder="组名"></jgp-text>
                </jgp-form-group>
            </jgp-query>
            <jgp-grid slot="2-1" _id="activeGroupGrid" _single="true" _check="false"
                      _record_tools="[{'icon':'edit','tip':'编辑','fn':'editList'},
                  {'icon':'plus','tip':'添加组项','fn':'addListItem'},
                  {'icon':'trash-o','tip':'删除','fn':'removeAttribute'}]"
                      _onclick="chooseList"></jgp-grid>

            <jgp-query slot="3-1" _id="attributeQueryFrom" _cols="12"
                       _auto="false"
                       _action="/sys/param-api-ctl/query-list-item"
                       _target="attributeGrid">
                <jgp-form-group _title="功能组项" _label_width="60px">
                    <jgp-text _label="复制标识" _name="activeKey" _col="6" _readonly="true"></jgp-text>
                </jgp-form-group>
            </jgp-query>

            <jgp-grid slot="4-1" _id="attributeGrid"
                      _record_tools="[{'icon':'edit','tip':'编辑','fn':'editItem'},
                      {'icon':'trash-o','tip':'删除','fn':'removeAttribute'}]">
            </jgp-grid>
        </jgp-div>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        function addGroup() {
            var selected = JGP.tree2('groupTree').getSelected();
            var parentId = -1;
            if (selected.length !== 0) {
                parentId = selected[0].id
            }

            var dialog = {
                'title': '添加组',
                'width': '500px',
                'height': '470px',
                'url': '/sys/param-ctl/edit-param-group?parentId=' + parentId,
                'callback': function (result) {
                    location.reload();
                }
            };
            JGP.$dialog(dialog);
        }

        function chooseGroup(args) {
            if(args.back.key){
                var query = JGP.query('activeGroupQueryForm');
                query.field('parentId',args.back.key);
                query.search();
            }
        }

        function chooseList(args) {
            var query = JGP.query('attributeQueryFrom');
            query.field('activeKey',args.back.record.activeKey);
            query.search();
        }

        function addList(args) {

            var dialog = {
                'title': '创建列表',
                'width': '500px',
                'height': '470px',
                'url': '/sys/param-ctl/edit-list?parentId=' + args.back.node.key,
                'callback': function (result) {

                }
            };
            JGP.$dialog(dialog);
        }

        function addListItem(args) {
            var dialog = {
                'title': '创建列表项',
                'width': '500px',
                'height': '470px',
                'url': '/sys/param-ctl/edit-list-item?parentId=' + args.back.record.id,
                'callback': function (result) {

                }
            };
            JGP.$dialog(dialog);
        }

        function editList(args) {
            var dialog = {
                'title': '创建列表项',
                'width': '500px',
                'height': '470px',
                'url': '/sys/param-ctl/edit-list?id=' + args.back.record.id+"&parentId="+args.back.record.parentId,
                'callback': function (result) {
                }
            };
            JGP.$dialog(dialog);
        }

        function refreshCache() {
            JGP.$post("/sys/param-api-ctl/refresh-cache", {}, function (result) {
                if (result.flag) {
                    JGP.$alert("刷新成功");
                }
            })
        }
        
    </script>
[/@JGP.foot]